<?php
/**
 *
 * @author griever
 * @version
 */
require_once 'Base.php';
require_once 'Zend/Loader/PluginLoader.php';
require_once 'Zend/Controller/Action/Helper/Abstract.php';

/**
 * CheckActivationCode Action Helper
 *
 * @uses actionHelper Custom_Helper
 */
class Custom_Helper_CheckActivationCode extends Dummy_Helper_Base
{
	public function checkCode($user, $activation)	{
		if($user->activation == $activation){
			$register_date = $user->activation_date;
			$current_date = time();
			list($d,$t) = explode(' ',$register_date);
			$dateArr  = explode("-",$d);
			$timeArr = explode(":",$t);
			$date1Int = mktime($timeArr[0],$timeArr[1],$timeArr[2],$dateArr[1],$dateArr[2],$dateArr[0]) ;
			$date_diff = $current_date - $date1Int;

			if($date_diff/86400 >= 0 && $date_diff/86400 < 2){
				$user->activated=1;
				$user->UpdateRow();
				$success = 1;
			} else	{
				$success = 2;//Message::ACTIV_CODE_EXPIRED_CLK." <a href='".$this->view->url(array('controller'=>'user-ajax', 'action'=>'re-activate'))."'>".Message::HERE."</a> ".Message::TO_RECV_NEW_CODE;
			}
		} else	{
			$success = 3;//Message::ACTIV_CODE_INVALID;
		}
		return $success;
	}

	/**
	 * Strategy pattern: call helper as broker method
	 */
	public function direct($user, $activation){
		// TODO Auto-generated 'direct' method
		return $this->checkCode($user, $activation);
	}
}

